{include file="admin/head" /}
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">公告管理</a>
        <a>
          <cite>上传公告</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-form-item">
        <label for="" class="layui-form-label">公告标题</label>
        <div class="layui-input-block">
            <input type="text" id="title" class="layui-input" placeholder="请输入公告标题">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="" class="layui-form-label">公告内容</label>
        <div class="layui-input-block">
            <div id="editor"></div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn layui-btn-fluid" onclick="add()">提交</button>
        </div>
    </div>
    {if $Think.session.admin}
    <input type="hidden" id="author" name="author" value="{$Think.session.admin.username}">
    {else/}
    <input type="hidden" id="author" name="author" value="{$Think.session.teacher.realname}">
    {/if}
</div>

<script>var _hmt = _hmt || []; (function() {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
<script type="text/javascript" src="/static/lib/wangEditor-3.1.1/release/wangEditor.js"></script>
<script>
    var E = window.wangEditor
    var editor = new E('#editor')
    editor.customConfig.uploadFileName = 'images'
    editor.customConfig.uploadImgServer = "{:url('notice_upload')}"   // 使用 base64 保存图片
    // editor.customConfig.uploadFileName = 'images'
    // editor.customConfig.uploadImgServer = "{:url('feedback_img')}"
    // 或者 var editor = new E( document.getElementById('editor') )
    editor.create()
    function add() {
        $.post(
            "",
            {
                title:$('#title').val(),
                content:editor.txt.html(),
                author:$('#author').val()
            },
            function (data) {
                layui.use('layer', function(){
                    var layer = layui.layer;
                    if (data.statu==200){
                        layer.msg(data.msg);
                        $('#title').val('');
                        editor.txt.html('<p><br></p>')
                    } else {
                        layer.msg(data.msg);
                    }
                });
            }
        )
        // alert(editor.txt.html())
    }
</script>
</body>

</html>